#!/bin/sh
# Runs the fastest whisper-server this CPU can execute. The fast build uses
# instructions an older CPU lacks (AVX2 on x86-64, dotprod/fp16 on arm64) and
# would die there with SIGILL, so the generic build stays beside it.
dir=$(dirname "$(readlink -f "$0")")
case "$(uname -m)" in
  x86_64) flag=avx2; fast=whisper-server-x64-avx2; generic=whisper-server-x64-generic ;;
  aarch64|arm64) flag=asimddp; fast=whisper-server-arm64-dotprod; generic=whisper-server-arm64-generic ;;
  *) echo "whisper-server: unsupported architecture $(uname -m)" >&2; exit 1 ;;
esac
if [ -z "$WHISPER_GENERIC" ] && [ -x "$dir/$fast" ] && grep -qw "$flag" /proc/cpuinfo 2>/dev/null; then
  exec "$dir/$fast" "$@"
fi
exec "$dir/$generic" "$@"
